<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>认识Promise</title>
</head>

<body>
    <h4>// promise的三种状态<hr>
        // 在异步任务未完成时为 pending 待定状态<hr>
        // resolve() => 'fulfilled状态-已兑现' => then() <hr>
        // reject() => 'rejected状态-已拒绝' => catch() <hr>
    </h4>
    <script>
        // 创建Promise对象
        const promise = new Promise((resolve, reject) => {
            // 执行异步代码
            setTimeout(() => {
                reject(new Error('请求失败'))
            }, 2000);
        })

        // 获取结果
        promise.then(result => {
            console.log(result);
        }).catch(result => {
            console.log(result);
        })
    </script>
</body>

</html>